<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>全局变量</title>
</head>

<body>
    <p>全局变量在任何脚本和函数内均可访问。</p>
    <p id="demo"></p>
    <script>
        var carName = "Volvo";
        myFunction();
        function myFunction() {
            document.getElementById("demo").innerHTML =
                "我可以显示 " + carName;
        }
    </script>
</body>

</html>